<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body id="body">
    <h2>点击查询-----查询搜索的内容</h2>
    <input type="text" id="inp">
    <button id="btn">查询</button>

    <script>
        //1点击事件
        document.getElementById('btn').onclick=function(){
            //就获取用户输入的内容
            let name=document.getElementById('inp').value
            //创建script，访问百度接口
            let script=document.createElement('script')
            script.src='http://suggestion.baidu.com/su?cb=callback&wd='+name
            console.log(script)
            //插入body
            document.getElementById('body').appendChild(script)

        }
        //2定义接受函数
        function callback(res){
            console.log(res)
        }
    </script>
</body>
</html>